package com.yikaiye.android.yikaiye.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.ItemGdInfoBinding;
import com.yikaiye.android.yikaiye.model.company.GsBaseInfoModel;
import com.yikaiye.android.yikaiye.utils.CommonUtil;

/**
 * 股东信息
 */
public class GdInfoAdapter extends BaseQuickAdapter<GsBaseInfoModel.GdInfoModel, DataBindingHolder<ItemGdInfoBinding>> {

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemGdInfoBinding> itemGdInfoBindingDataBindingHolder, int position, @Nullable GsBaseInfoModel.GdInfoModel gdInfoModel) {
        ItemGdInfoBinding binding = itemGdInfoBindingDataBindingHolder.getBinding();
        if (gdInfoModel != null) {
            if (position % 3 == 0) {
                binding.tvSurname.setBackgroundResource(R.drawable.shape_c5ace9_2dp);
            } else if (position % 3 == 1) {
                binding.tvSurname.setBackgroundResource(R.drawable.shape_93a4e1_2dp);
            }
            if (position % 3 == 2) {
                binding.tvSurname.setBackgroundResource(R.drawable.shape_d1b194_2dp_bg);
            }
            if (!TextUtils.isEmpty(gdInfoModel.getStockName())) {
                binding.tvSurname.setText(gdInfoModel.getStockName().substring(0, 1));
                binding.tvGdName.setText(gdInfoModel.getStockName());
            }
            if (!TextUtils.isEmpty(gdInfoModel.getStockPercent())) {
                binding.tvStockPercent.setText(CommonUtil.getResultForDouble(Double.parseDouble(gdInfoModel.getStockPercent()) * 100) + "%");
            }
            binding.tvTotalShouldCapital.setText(CommonUtil.setText(gdInfoModel.getTotalShouldCapi()));
            binding.tvTotalRealCapital.setText(CommonUtil.setText(gdInfoModel.getTotalRealCapi()));
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemGdInfoBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_gd_info, viewGroup);
    }
}
